package logic

import (
	"context"
	"doctor-medicine-system/doctorrpc/doctorrpc"
	"doctor-medicine-system/doctorrpc/internal/svc"
	"doctor-medicine-system/modles/mysql"

	"github.com/zeromicro/go-zero/core/logx"
)

type StaticAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewStaticAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *StaticAddLogic {
	return &StaticAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *StaticAddLogic) StaticAdd(in *doctorrpc.StaticAddRequest) (*doctorrpc.StaticAddResponse, error) {
	// todo: add your logic here and delete this line

	var static = mysql.Static{
		Name:    in.Name,
		Type:    in.Types,
		Address: in.Address,
		UserId:  in.UserId,
	}

	err := static.StaticAdd(mysql.DB)
	if err != nil {
		return nil, err
	}

	return &doctorrpc.StaticAddResponse{
		StaticId: int64(static.ID),
	}, nil
}
